package edu.zzuli.common;
/**
 * @author tianshaojie
 * @date 2011-7-16
 * @discription : 分页类
 */
public class Pagination {

	private int pageSize; 		// 每页显示的行数
	
	private int currentPage; 	// 当前页号
	
	private int totalPages; 	// 总页数
	
	private int totalRows; 		// 总行数
	
	private int pageRowBegin;	// 返回本页记录开始位置
	
	private int pageRowEnd;		// 返回本页记录结束位置
	
	public Pagination(){}
	
	public Pagination(int pageSize,int currentPage) {
		this.pageSize = pageSize;
		this.currentPage = currentPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
		
		if (this.totalRows % this.pageSize == 0)
			this.totalPages = (this.totalRows / this.pageSize);
		else {
			this.totalPages = (this.totalRows / this.pageSize + 1);
		}
		
		if (this.currentPage > 0) {
			this.pageRowBegin = ((this.currentPage - 1) * this.pageSize + 1);
		} else {
	    	this.pageRowBegin = 0;
	    }
		
		if (this.currentPage < this.totalPages) {
			this.pageRowEnd = (this.pageRowBegin + this.pageSize - 1);
		} else {
			this.pageRowEnd = (this.pageRowBegin + (this.totalRows - 1) % this.pageSize);
			if (this.pageRowEnd < 0) {
				this.pageRowEnd = 0;
			}
		}
	}

	public int getPageRowBegin() {
		return pageRowBegin;
	}

	public int getPageRowEnd() {
		return pageRowEnd;
	}

	public void setPageRowBegin(int pageRowBegin) {
		this.pageRowBegin = pageRowBegin;
	}

	public void setPageRowEnd(int pageRowEnd) {
		this.pageRowEnd = pageRowEnd;
	}

}
